<html>
    <head>
        <title>提取PNR形成订单</title>
    </head>
    <body>
        <div id="rt_pnr_form">
        </div>
        <div id="rtOrdersGrid" class="x-form-item">
        </div>
        <div id="rtTicketsGrid" class="x-form-item">
        </div>
        <script>
            var current_order_id; //当前选择的order的id
            var current_ticket_id; //当前选择的ticket的id
            var current_order_status; //当前order的状态
            var current_ticket_status; //当前ticket的状态
            var ordersrow;
            var ticketsrow;
            Ext.onReady(function(){
                var gn = new Ext.form.Radio({
                    //fieldLabel: '国内',
                    hideLabel: true,
                    name: 'rt_type',
                    boxLabel: '国内',
                    checked: true,
                    inputValue: ''
                });
                var gj = new Ext.form.Radio({
                    //fieldLabel: '国际',
                    hideLabel: true,
                    name: 'rt_type',
                    boxLabel: '国际',
                    checked: false,
                    inputValue: ''
                });
                var web = new Ext.form.Radio({
                    //fieldLabel: '网上',
                    hideLabel: true,
                    name: 'rt_type',
                    boxLabel: '网上',
                    checked: false,
                    inputValue: ''
                });
                var pnrField = new Ext.form.TextField({
                    fieldLabel: 'PNR',
                    name: 'pnr',
                    allowBlank: false,
                    //anchor: '90%',
                    width: 80
                });

                //提交按钮
                var submitButton = new Ext.Button({
                    text: '提取',
                    handler: function(){
                        if (formPanel.form.isValid()) {
                            var type = "gn";
                            if (gj.checked){
                                type = "gj";
                            }else if (web.checked){
                                type = "web";
                            }
                            var pnr = pnrField.getValue();
                            if (pnr.length == 5) {
                                orderds.baseParams.type = type;
                                orderds.baseParams.pnr = pnr;
                                orderds.reload();
                            }
                            else {
                                Ext.MessageBox.alert('提示信息', '输入的PNR有误,必须是5为字母或数字组成.');
                            }
                        }
                    }
                })

                var formPanel = new Ext.form.FormPanel({
                    //baseCls: 'x-plain',
                    labelWidth: 75,
                    width: '100%',
                    frame: true,
                    title: '提取PNR信息形成订单',
                    labelAlign: 'right',
                    items: [{
                            layout: 'column',
                            border: false,
                            items: [{
                                    columnWidth: .2,
                                    layout: 'form',
                                    border: false,
                                    items: [pnrField]
                                }, {
                                    columnWidth: .07,
                                    layout: 'form',
                                    border: false,
                                    items: [gn]
                                }, {
                                    columnWidth: .07,
                                    layout: 'form',
                                    border: false,
                                    items: [gj]
                                }, {
                                    columnWidth: .1,
                                    layout: 'form',
                                    border: false,
                                    items: [web]
                                }, {
                                    columnWidth: .3,
                                    layout: 'form',
                                    border: false,
                                    items: [submitButton]
                                }]
                        }]
                });

                formPanel.render('rt_pnr_form');

                //############## 订单Grid ##############
                var ordercm = new Ext.grid.ColumnModel([new Ext.grid.RowNumberer(), {
                        header: '编号',
                        dataIndex: 'id',
                        hidden: true
                    }, {
                        header: '订单编号',
                        dataIndex: 'order_no',
                        width: 120
                    }, {
                        header: 'PNR',
                        dataIndex: 'pnr',
                        width: 50
                    }, {
                        header: '客户名称',
                        dataIndex: 'customer',
                        width: 70
                    }, {
                        header: '订单状态',
                        dataIndex: 'status',
                        width: 60
                    }, {
                        header: '总金额',
                        dataIndex: 'price_sum',
                        width: 60
                    }, {
                        header: '乘机日期',
                        dataIndex: 'fly_date',
                        width: 90
                    }, {
                        header: '起飞时间',
                        dataIndex: 'fly_time',
                        width: 60
                    }, {
                        header: '预定员',
                        dataIndex: 'creator',
                        width: 60
                    }, {
                        header: '预定时间',
                        dataIndex: 'created_at',
                        width: 120,
                        renderer: Ext.util.Format.dateRenderer('Y-m-d H:i')
                    }, {
                        header: '确认时间',
                        dataIndex: 'affirm_date',
                        width: 90,
                        renderer: Ext.util.Format.dateRenderer('Y-m-d')

                    }]);

                var orderds = new Ext.data.Store({
                    proxy: new Ext.data.HttpProxy({
                        url: '/orders/getOrderInfoByPnr'
                    }),
                    reader: orderReader
                });

                var ordergridpanel = new Ext.grid.GridPanel({
                    el: 'rtOrdersGrid',
                    ds: orderds,
                    cm: ordercm,
                    loadMask: true,
                    autoWidth: true,
                    collapsible: true,
                    animCollapse: true,
                    height: 100,
                    //frame: true,
                    title: '订单信息'
                });

                ordergridpanel.getStore().on({
                    //beforeload: function(){
                    load: function(){
                        var result = this.reader.jsonData.info;
                        if (result.indexOf("成功") < 0) {
                            Ext.MessageBox.alert("提取失败", "" + result);
                        }
                        else {
                            Ext.MessageBox.alert("提取成功", "" + result);
                        }
                        var oid = this.reader.jsonData.orderid;
                        if (oid != "") {
                            ticketds.baseParams.id = oid;
                            ticketds.reload();
                        }
                    }
                });

                ordergridpanel.render();
                //orderds.load();

                //双击订单查看票详细
                ordergridpanel.on('rowdblclick', function(ordergridpanel, rowIndex, e){
                    var current_order_selected = orderds.data.items[rowIndex].id;
                    ordersrow = orderds.getById(current_order_selected);//ds为绑定到grid的数据源
                    current_order_id = ordersrow.get("id");
                    current_order_status = ordersrow.get("status");
                    ticketds.baseParams.id = current_order_id;
                    ticketds.reload();
                });
                //订单右键菜单
                ordergridpanel.on('rowcontextmenu', function(customergridpanel, rowIndex, e){
                    var current_order_selected = orderds.data.items[rowIndex].id;
                    ordersrow = orderds.getById(current_order_selected);//ds为绑定到grid的数据源
                    current_order_id = ordersrow.get("id");
                    current_order_status = ordersrow.get("status");
                    e.preventDefault();
                    rightClick.showAt(e.getXY());
                });

                //############ 订单-右键菜单 ##########
                var rightClick = new Ext.menu.Menu({
                    items: [{
                            handler: rightMenu1Fn,
                            text: '【修改订单】'
                        }, {
                            handler: rightMenu4Fn,
                            text: '【提取PNR】'
                        }]
                });
                function rightMenu1Fn(){
                    ModOrder(orderds, current_order_id, ticketds);
                }
                function rightMenu4Fn(){
                    showPnrInfo(current_order_id);
                }

                //### 机票Grid ###
                var ticketcm = new Ext.grid.ColumnModel([new Ext.grid.RowNumberer(), {
                        header: '编号',
                        dataIndex: 'id',
                        sortable: true
                    }, {
                        header: 'PNR',
                        dataIndex: 'pnr',
                        sortable: true,
                        width: 60
                    }, {
                        header: '旅客姓名',
                        dataIndex: 'passenger_name',
                        sortable: true,
                        width: 70
                    }, {
                        header: '证件号码',
                        dataIndex: 'card',
                        sortable: true,
                        width: 140
                    }, {
                        header: '乘客类型',
                        dataIndex: 'ticket_type',
                        sortable: true,
                        width: 60
                    }, {
                        header: '票号',
                        dataIndex: 'ticket_no',
                        sortable: true,
                        width: 110
                    }, {
                        header: '状态',
                        dataIndex: 'status_type',
                        sortable: true,
                        width: 40
                    }, {
                        header: '出票状态',
                        dataIndex: 'status',
                        sortable: true,
                        width: 60
                    }, {
                        header: '航班号',
                        dataIndex: 'air_no',
                        sortable: true,
                        width: 60
                    }, {
                        header: '航程',
                        dataIndex: 'fromto',
                        sortable: true,
                        width: 60
                    }, {
                        header: '乘机日期',
                        dataIndex: 'fly_date',
                        sortable: true,
                        width: 70
                    }, {
                        header: '起飞时间',
                        dataIndex: 'fly_time',
                        sortable: true,
                        width: 60
                    }, {
                        header: '舱位',
                        dataIndex: 'position',
                        sortable: true,
                        width: 40
                    }, {
                        header: '机票价格',
                        dataIndex: 'price',
                        sortable: true,
                        width: 60
                    }, {
                        header: '机场费税',
                        dataIndex: 'airdrome_tax',
                        sortable: true,
                        width: 60
                    }, {
                        header: '附加费',
                        dataIndex: 'fuel_tax',
                        sortable: true,
                        width: 50
                    }, {
                        header: 'F',
                        dataIndex: 'price_F',
                        sortable: true,
                        width: 50
                    }, {
                        header: '保险份数',
                        dataIndex: 'insurance_number',
                        sortable: true,
                        width: 60
                    }, {
                        header: '保险F',
                        dataIndex: 'insurance_F',
                        sortable: true,
                        width: 50
                    }, {
                        header: '其他',
                        dataIndex: 'other',
                        sortable: true,
                        width: 50
                    }, {
                        header: '积分',
                        dataIndex: 'point',
                        sortable: true,
                        width: 50
                    }, {
                        header: '合计',
                        dataIndex: 'total_price',
                        sortable: true,
                        width: 60
                    }]);

                //隐藏ticket数据库id
                ticketcm.setHidden(1, !ticketcm.isHidden(1));
                var ticketProxy = new Ext.data.HttpProxy({
                    //url: '/orders/getTicketsByOrderID?showCancelTicket=no'
                    url: '/orders/getTicketsByOrderID'
                });

                var ticketds = new Ext.data.Store({
                    proxy: ticketProxy,
                    reader: ticketReader
                });

                var ticketgridpanel = new Ext.grid.GridPanel({
                    el: 'rtTicketsGrid',
                    ds: ticketds,
                    cm: ticketcm,
                    loadMask: true,
                    autoWidth: true,
                    collapsible: true,
                    animCollapse: false,
                    height: 300,
                    //frame: true,
                    title: '航班信息'
                });

                ticketgridpanel.render();
                //ticketds.load();

                //############ 票-右键菜单 ##########
                function ticketRightMenu1(){
                    ModTicket(ticketds, current_ticket_id, orderds);
                }
                function ticketRightMenu2(){
                    var current_passenger_name = ticketsrow.get("passenger_name");
                    cancelTicket(current_ticket_status, current_ticket_id, current_passenger_name, ticketds);
                }
                var ticketRightClick = new Ext.menu.Menu({
                    items: [{
                            handler: ticketRightMenu1,
                            text: '【编辑修改】'
                        }, {
                            handler: ticketRightMenu2,
                            text: '【取消乘客】'
                        }]
                });
                ticketgridpanel.on('rowcontextmenu', function(ticketgridpanel, rowIndex, e){
                    var current_ticket_selected = ticketds.data.items[rowIndex].id;
                    ticketsrow = ticketds.getById(current_ticket_selected);//ds为绑定到grid的数据源
                    current_ticket_id = ticketsrow.get("id");
                    current_ticket_status = ticketsrow.get("status");
                    e.preventDefault();
                    ticketRightClick.showAt(e.getXY());
                });

            })
        </script>
    </body>
</html>
